<html>
<head>
<title>Sample JWS Signing With PKCS#1 private key</title>
<script language="JavaScript" type="text/javascript" src="../jsrsasign-all-min.js"></script>

<style type="text/css">
TD  {vertical-align: top; border: solid 1px #000000; }
</style>
<script language="JavaScript" type="text/javascript">

function _genJWS() {
  var sHead = newline_toDos(document.form1.jwshead1.value);
  var head = KJUR.jws.JWS.readSafeJSONString(sHead);
  var sPayload = newline_toDos(document.form1.jwspayload1.value);
  var sPemPrvKey = document.form1.pemprvkey1.value;

  var jws = new KJUR.jws.JWS();
  var sResult = null;
  try {
    var prv = KEYUTIL.getKey(sPemPrvKey);
    sResult = KJUR.jws.JWS.sign(head.alg, sHead, sPayload, prv);
    document.form1.jwsgenerated1.value = sResult;
  } catch (ex) {
    alert("Error: " + ex);
  }
}
</script>
</head>

<body>
<h1>Sample JWS Signing Application</h1>

<p>
Default values are cited from <a href="http://tools.ietf.org/html/draft-jones-json-web-signature-04#appendix-A.2" target="_blank">
"draft-jones-json-web-signature-04 Annex.2"</a>.
</p>

<form name="form1">
<table width="100%">
<tbody>
<tr><td rowspan="3">Input</td><td>JWS Header</td><td colspan="2">
<textarea name="jwshead1" rows="3" cols="100">{"alg":"PS256"}</textarea></td></tr>
<tr><td>JWS Payload</td><td colspan="2">
<textarea name="jwspayload1" rows="3" cols="100">{"iss":"joe",
 "exp":1300819380,
 "http://example.com/is_root":true}</textarea>
</td></tr>
<tr><td>Signing PKCS#1 RSA Private Key</td><td colspan="2">
<textarea name="pemprvkey1" rows="10" cols="80">-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA4qiw8PWs7PpnnC2BUEoDRcwXF8pq8XT1/3Hc3cuUJwX/otNe
fr/Bomr3dtM0ERLN3DrepCXvuzEU5FcJVDUB3sI+pFtjjLBXD/zJmuL3Afg91J9p
79+Dm+43cR6wuKywVJx5DJIdswF6oQDDzhwu89d2V5x02aXB9LqdXkPwiO0eR5s/
xHXgASl+hqDdVL9hLod3iGa9nV7cElCbcl8UVXNPJnQAfa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7SlFdc7S1viH4xzUOkjZH2Hyl+OLOQTOYd3
kp+AgfXpg8an4ujAUP7mu8xaxns7zsNzr+BCgYwXmIlhWz2Aiz2UeL/IsfOpRwuV
801xAoGADQB84MJe/X8xSUZQzpn2KP/yZ7C517qDJjComGe3mjVxTIT5XAaa1tLy
T4mvpSeYDJkBD8Hxr3fB1YNDWNbgwrNPGZnUTBNhxIsNLPnV8WySiW57LqVXlggH
vjFmyDdU5Hh6ma4q+BeAqbXZSJz0cfkBcBLCSe2gIJ/QJ3YJVQI=
-----END RSA PRIVATE KEY-----</textarea>
</td></tr>
<tr><td colspan="4">
<input type="button" value="Generate JWS Signature&darr;" onClick="_genJWS();"/>
</td></tr>
<tr><td colspan="2">Output JWS Signature</td><td colspan="2">
<textarea name="jwsgenerated1" cols="100" rows="6" readonly></textarea>
</td></tr>
</tbody>
</table>

</form>
<h3>USAGE</h3>
<ol>
<li>Just press "Generate JWS Signature" button.</li>
<li>You can specify signature algorithm name such as "RS256"(SHA256withRSA), "RS512"(SHA512withRSA), "PS256"(SHA256withRSAPSS), "PS512"(SHA512withRSAPSS). 
If it isn't un-supported value, it will raise an error.</li>
<li>If malformed JWS Head is specified, it will raise an error.</li>
<li>As for JWS signature verification, please see <a href="sample_verify3.html">this sample</a>.</li>
</ol>

<center>
Copyright &copy; 2013-2016 Kenji Urushima, Dave All Rights Reserved.
</center>

<div align="right">
<a href="index.html">Go back to index</a>
</div>

</body>
</html>
